/**
 * 
 */
package info.niwota.webshot;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;

/**
 * @author qiangli
 * 
 */
public class WebPickActivity extends WebBaseActivity {

	private static final String TAG = "WebPickActivity";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		if (Debug.DEBUG) {
			Log.d(TAG, " " + savedInstanceState);
		}
		//
		requestWindowFeature(Window.FEATURE_PROGRESS);
		requestWindowFeature(Window.FEATURE_LEFT_ICON);

		setContentView(R.layout.browser);

		getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
				R.drawable.browser);
		//
		initRes(savedInstanceState);
		initWebview(savedInstanceState);
		init(savedInstanceState);
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (frameSnapshot.getVisibility() == View.VISIBLE) {
				showWeb();
				return true;
			}
			// frameWeb visible
			webview.stopLoading();
			//
			setResult(RESULT_CANCELED);
			finish();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}
	@Override
	protected void doAccept() {
		try {
			//
			Uri uri = (imagefile == null ? null : Uri.parse("file://"
					+ imagefile.getPath()));
			Intent data = new Intent(null, uri);
			data.putExtra("url", webview.getUrl());
			data.putExtra("title", webview.getTitle());
			setResult(RESULT_OK, data);
			//
			addImage();
		} catch (Exception e) {
			e.printStackTrace();
		}
		//
		finish();
	}

	@Override
	protected void initRes(Bundle savedInstanceState) {
		super.initRes(savedInstanceState);
		//
		btnShare.setVisibility(View.GONE);
	}
}
